<div id="listNotifications"></div>
<?php if(count($messages)>0):?>
	 <fieldset style="width:100%; clear:both"><legend>Nouvelles</legend>
	 <?php include_partial('messages/showMessagesList', array('messages' => $messages));?>
	 </fieldset>
<?php endif;?>

<script type="text/javascript">
$(document).ready(function() 
		{
			refreshMessages();
			$(".fancyMessage").fancybox({
				type: 'ajax',
				fitToView	: true,
				autoSize	: true,
				openEffect	: 'none',
				closeEffect	: 'none',
				afterClose	: function() {
					refreshMessages();
					return;
			    }
			});			
		});

function refreshMessages(){
	$('#listNotifications').empty();
	$('#listNotifications').append('<div id="loader"></div>');
	$('#loader').append('<img src="/images/ajax-loader.gif" alt="' + __('wait please...') + '" id="ajaxloader" />');
	var xhr = getXmlHttpRequest2();
	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4) {
			if (xhr.status == 200) {
				$('#listNotifications').append(xhr.responseText);
			} else {
				$('#listNotifications').append('Erreur à la récuperation de vos messages');
			}
			$('#loader').remove();
		}
	};
	xhr.open("POST","<?php print url_for('ajax/getListNotifications'); ?>",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send();
	
}

</script>